import 'dart:collection';

import 'package:flutter/material.dart';
import 'package:jm_flutter/jm_flutter.dart';

import '../model/app_file_desc.dart';

class AppDirectoryNavigationBar extends StatelessWidget {
  final AppFileDesc rootDir;
  final Queue<AppFileDesc> dirQueue;
  final VoidCallback? onTapRootDir;
  final ValueChanged<AppFileDesc> onTapDir;

  const AppDirectoryNavigationBar(
      {super.key,
      required this.dirQueue,
      required this.rootDir,
      this.onTapRootDir,
      required this.onTapDir});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 40,
      width: double.infinity,
      alignment: Alignment.centerLeft,
      child: ListView(
        //shrinkWrap: true,
        scrollDirection: Axis.horizontal,
        padding: const EdgeInsets.only(left: 8, top: 4, bottom: 4),
        reverse: true,
        shrinkWrap: true,
        children: [
          for (int i = dirQueue.length - 1; i >= 0; i--) ...[
            InkWell(
              child: Container(
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(8),
                  color: Colors.grey[300],
                ),
                child: Padding(
                  padding: const EdgeInsets.all(6.0),
                  child: MyText.sub(
                    dirQueue.elementAt(i).name,
                    size: 14,
                    weight: FontWeight.bold,
                  ),
                ),
              ),
              onTap: () => onTapDir(dirQueue.elementAt(i)),
            ),
            Icon(
              CupIcons.chevron_forward,
              color: Colors.grey[400],
              size: 20,
            ),
          ],
          InkWell(
            onTap: onTapRootDir,
            child: Container(
              alignment: Alignment.center,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(8),
                color: Colors.grey[300],
              ),
              child: Padding(
                padding: const EdgeInsets.all(6.0),
                child: MyText.sub(
                  rootDir.name,
                  size: 14,
                  weight: FontWeight.bold,
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
